import React, { useEffect, useState } from 'react'
import api from '@/api'
import { useNavigate } from 'react-router-dom'
import {
    Space, Table, Tag, Image, Button, Drawer, message,
    Cascader,
    Checkbox,
    DatePicker,
    Form,
    Input,
    InputNumber,
    Radio,
    Select,
    Switch,
    TreeSelect,
    Upload,
    Pagination,
    Card
} from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { SearchOutlined, EditOutlined, CloseOutlined, PlusOutlined } from '@ant-design/icons';
export default function Orderhandle() {
    const nav = useNavigate()
    const [list, setList] = useState([])
    const columns: ColumnsType<any> = [
        {
            title: '服务名',
            dataIndex: 'servegoodsname',
            key: 'servegoodsname'
        },
        {
            title: '价格',
            dataIndex: 'price',
            key: 'price'
        },
        {
            title: '结束时间',
            dataIndex: 'endtime',
            key: 'endtime'
        },
        {
            title: '是否接单',
            dataIndex: '',
            key: 'img',
            render: (_, item) => {
                if (item.refuse) {
                    let ary = item.refuse.split(',')
                    let flag = true
                    ary.forEach((items: any) => {
                        if (items == item.serveid) {
                            flag = false
                        }
                    })
                    if (flag) {
                        return (

                            <Space>
                                <Button onClick={() => { accpect(item.id) }} >接单</Button> <Button type="primary" danger onClick={() => { refuse(item.id) }}>拒绝</Button>
                            </Space>

                        )
                    } else {
                        return (<Space>
                            <Button type="primary" >已拒绝</Button>
                        </Space>)

                    }
                } else {
                    return (

                        <Space>
                            <Button onClick={() => { accpect(item.id) }}>接单</Button> <Button type="primary" danger onClick={() => { refuse(item.id) }}>拒绝</Button>
                        </Space>

                    )
                }




            }

        },
    ]
    async function accpect(args: any) {
        console.log(args);
        const res = await api.worker.accpectOrder({ id: args })
        console.log(res.data.msg);
        getList()
        nav('/orderprocess')
    }
    async function refuse(args: any) {
        const res = await api.worker.refuseOrder({ id: args })
        console.log(res.data.msg);
        getList()

    }
    async function getList() {
        const res = await api.worker.getorderRobList()
        console.log(res.data.data);
        setList(res.data.data)
    }
    useEffect(() => {
        getList()
    }, [])
    return (
        <div>
            <Card>

                <Table columns={columns} dataSource={list} pagination={false}>

                </Table>
            </Card>
        </div>
    )
}
